package cn.doit.day04

object _03_简单算子2 {
  def main(args: Array[String]): Unit = {
    val arr: List[String] = List("hadoop","hadoop","hive","hive","hadoop")
    //需求，将arr中的偶数过滤出来 Array(2,4)
//    val res: List[Int] = arr.filter(_ % 2 == 0)
    //foreach ==> 将集合中的每一个元素都取出来 然后作用在函数上，都作用一遍 ==》穿进去的函数返回值类型必须得是unit
    //经常用来打印
//    res.foreach(println)

    //聚合类的算子
    /*val iterator: Iterator[List[Int]] = arr.grouped(3)
    for (elem <- iterator) {
      println(elem)
    }*/
    //将相同的单词都收集起来了 key list[]=>所有和key相同的单词
    val map: Map[String, List[String]] = arr.groupBy(word => word)
    map.foreach(println)

    val ps: List[Pers] = List(
      Pers(1, "zss", "male"),
      Pers(2, "dalang", "male"),
      Pers(3, "liuyan", "female"),
      Pers(4, "tangyan", "female"),
      Pers(2, "dalang", "male"),
      Pers(1, "zss", "male"),
      Pers(3, "liuyan", "female"),
      Pers(4, "tangyan", "female")
    )

//    val map1: Map[String, List[Pers]] = ps.groupBy(_.gender)

    //检查作业

  }

}

case class Pers(id:Int,name:String,gender:String)
